package com.magic.web.common.controller;

import net.minidev.json.JSONObject;
import org.junit.Test;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

/**
 * @description
 * @author wm
 * @date 2020/12/28
 */

public class WebMagicTestController {

    private static SimpleDateFormat YMM = new SimpleDateFormat("yyyy-MM");

   /* public static void main(String[] args) throws ParseException {
        *//*SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String date = format.format(new Date());
        System.out.println(date);
        Date parse = format.parse(date);
        System.out.println(parse);*//*
        *//*BigDecimal bigDecimal = BigDecimal.valueOf(1).setScale(2);
        BigDecimal bigDecimal2 = new BigDecimal(2).setScale(2);
        BigDecimal divide = bigDecimal.divide(bigDecimal2, 2, RoundingMode.HALF_UP);
        System.out.println(divide);*//*
        String a = "2020122911532411.jpg".replace("+", "%");
        String replace = a.replace("+", "%");
        System.out.println(a);
        System.out.println(replace);

    }*/

    @Test
    public void test01() {
        BigInteger bigInteger = new BigInteger("1");
        BigInteger integer = BigInteger.probablePrime(2, new Random());
        System.out.println(integer);
        System.out.println(bigInteger);
    }

    @Test
    public void test02() {
        String a = "523.023";
        BigDecimal bigDecimal = new BigDecimal(a);
        System.out.println(bigDecimal);
    }

    @Test
    public void test03() {
        Integer a = 3;
        Integer b = 4;
        double c = a + b;
        System.out.println(c);
    }

    @Test
    public void test04() {
        Boolean flag = true;
        int count = 0;
        while (flag) {
            count++;
            System.out.println("递归");
            if (count > 10) {
                flag = false;
            }
        }
    }

    @Test
    public void test05() {
        String a = "PDAA202035020000394525";
        String b = a.substring(0, 8) + "**********" + a.substring(18, a.length());
        System.out.println(b);
        System.out.println(a);
    }

    @Test
    public void test06() {
        Enumeration<String> days = null;
        Vector<String> dayName = new Vector<String>();
        dayName.add("1");
        dayName.add("2");
        dayName.add("3");
        dayName.add("4");
        dayName.add("5");
        dayName.add("6");
        dayName.add("7");
        dayName.add("8");
        days = dayName.elements();
        while (days.hasMoreElements()) {
            System.out.println(days.nextElement());
        }
    }

    @Test
    public void test08() {
        String a = "123456789123456789";
        System.out.println(a.length());
        if (a.length() == 18) {
            a = a.substring(0, 4) + "" + a.substring(12, a.length());
            System.out.println(a);
        }
    }

    @Test
    public void test09() {
        String date = DateUtils.getDateBefore(new Date(), 2);
        String start_date = date + " 00:00:00";
        String end_date = date + " 23:59:59";
        System.out.println(start_date);
        System.out.println(end_date);
    }

    @Test
    public void test10() {
        String IDCard = "41052319990523301X";
        String regix = "\\d{17}[0-9Xx]|\\d{15}";
        boolean compile = Pattern.compile(regix).matcher(IDCard).matches();
        System.out.println(compile);
        BigDecimal bigDecimal = new BigDecimal(12);
        System.out.println(bigDecimal);
        BigDecimal a = new BigDecimal(600.000);
        BigDecimal decimal = new BigDecimal(10);
        BigDecimal divide = decimal.multiply(new BigDecimal(1000)).setScale(3);
        System.out.println(a);
        System.out.println(divide);
        if (a.compareTo(divide) == 1) {
            System.out.println("1");
        } else {
            System.out.println("2");
        }
    }

    @Test
    public void test11() throws Exception {
        String Url = "https://demoapp.xmparking.net/iparking-unify-api/coupon/assign";
        JSONObject requeststr = new JSONObject();
        requeststr.put("appId", "CPM00XZ0YJ64IM");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("phone", "15959695475");
        jsonObject.put("assignSeq", "AS2021030100001");
        jsonObject.put("batNo", "0d88e4ab931b44b192b3766baedf532c");
        jsonObject.put("number", 5);
        requeststr.put("data", jsonObject);
        requeststr.put("sign", "ZjY5ZDgzYjg0YmZjMjZmOGU3MmE2Mjk0NDJjYjhhOTI=");
        requeststr.put("timestamp", "1614563853676");
        requeststr.put("version", "1.0");
        String s = HttpUtils.sendMessageByPost(Url, requeststr.toJSONString());
        System.out.println(s);
    }

    @Test
    public void test12() throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        String now = simpleDateFormat.format(new Date());
        String lastMonthEnd = DateUtils.getDateBefore(new Date(), 1);
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MONTH, 1);
        calendar.add(Calendar.MONTH, 0);
        String format = sdf.format(calendar.getTime());
        calendar.add(Calendar.MONTH, -1);
        String f = sdf.format(calendar.getTime());
        String lastMonthStart = simpleDateFormat.format(calendar.getTime());
        System.out.println(f);
        System.out.println(format);
        System.out.println(lastMonthStart);
        System.out.println(lastMonthEnd);
        System.out.println(now);
    }

    @Test
    public void test13() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        Date date = new Date();
        calendar.setTime(date);
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (1 == week) {
            System.out.println(week);
            System.out.println("1:" + sdf.format(calendar.getTime()));
            calendar.add(Calendar.DATE, -1);
            System.out.println(sdf.format(calendar.getTime()));
            calendar.add(Calendar.DATE, -6);
            System.out.println(sdf.format(calendar.getTime()));
        /*String sunday = DateUtils.getDateBefore(date, 1);
        String monday = DateUtils.getDateBefore(date, 7);
        System.out.println(sunday);
        System.out.println(monday);*/
        }
    }

    @Test
    public void test14() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Calendar lastMonth = Calendar.getInstance();
        lastMonth.set(Calendar.MONTH, 1);
        lastMonth.add(Calendar.MONTH, -1);
        //上个月第一天
        String lastMonthStart = simpleDateFormat.format(lastMonth.getTime());
        System.out.println(lastMonthStart);
    }

    @Test
    public void test15() {
        BigDecimal cxb_j = new BigDecimal(9.65);
        BigDecimal cxb_s = new BigDecimal(5.65);
        BigDecimal cxb_jq = new BigDecimal(9.25);
        BigDecimal cxb_sy = new BigDecimal(6.25);
        BigDecimal cxbc_j = cxb_jq.subtract(cxb_j).setScale(2, BigDecimal.ROUND_DOWN).abs();
        BigDecimal cxbc_s = cxb_sy.subtract(cxb_s).setScale(2, BigDecimal.ROUND_DOWN).abs();
        //System.out.println(cxbc_j);
        //System.out.println(cxbc_s);
        String msgj = "上升（" + cxbc_j + "）；";
        String msgs = "下降（" + cxbc_s + "）。";
        String msg = "您好，上月投保查询比情况为：上月交强险查询比为（" + cxb_jq + "），环比上月" + msgj + "上月商业险查询比为（" + cxb_sy + "），环比上月" + msgs;
        System.out.println(msg);
    }

    @Test
    public void test16() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String now_date = format.format(new Date());
        now_date = now_date + " 11:00:00";
        try {
            boolean b = System.currentTimeMillis() >= sdf.parse(now_date).getTime();
            System.out.println(System.currentTimeMillis());
            System.out.println(sdf.parse(now_date).getTime());
            //System.out.println(format.parse(now_date).getTime());
            if (b) {
                System.out.println("0");
            } else {
                System.out.println("1");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test17() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入高度:");
        double height = scanner.nextDouble();
        System.out.println("请输入要计算的次数");
        int count = scanner.nextInt();
        double temp = 0;
        for (int i = 0; i < count; i++) {
            temp = height / 2;
            //height = height + temp;
            System.out.println("第" + (i + 1) + "次反弹的高度是" + temp);
        }
        System.out.println("总高度：" + height);
    }

    @Test
    public void test18() {
        ArrayList<Map<String, Object>> list = new ArrayList<>();
        String flag = "0";
        for (int i = 0; i < 10; i++) {
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put(String.valueOf(i),flag);
            list.add(hashMap);
        }
        System.out.println(list);
    }

    @Test
    public void test19() {
        char[] chars = new char[4];
        int a = 0;
        System.out.println(new String(chars,0,a));
    }

    @Test
    public void test20() throws ParseException {
        //String a = "2020-3";
        //String format = YMM.format(YMM.parse(a));
        //System.out.println(format);
        int key = 2;
        int i = key / 2;
        /*for (int i = 0; i < 100; i++) {
            i++;
        }*/
        System.out.println(i);
    }

    @Test
    public void test21() {
        String[] a = {};
        System.out.println(a.length);
    }

    @Test
    public void test22() {
        Calendar lastMonth = Calendar.getInstance();
        //lastMonth.set(Calendar.MONTH, -1);
        lastMonth.add(Calendar.MONTH, -2);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String month = sdf.format(lastMonth.getTime());
        System.out.println(month);
    }

    @Test
    public void test23() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());
        String dateBefore = DateUtils.getDateBefore(new Date(), 1);
        System.out.println(dateBefore);
        System.out.println(format);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入高度:");
        double height = scanner.nextDouble();
        System.out.println("请输入要计算的次数");
        int count = scanner.nextInt();
        double temp = 0;
        double height2 = height;
        for (int i = 0; i < count; i++) {
            temp = height2 / 2;
            height2 = temp;
            height = height+temp;
            System.out.println("第" + (i + 1) + "次反弹的高度是:" + height2);
        }
        System.out.println("总高度：" + height);
    }
}
